/*KypxrnTlCsNW6raC5wgkoL6MjbkvcYxunKIWAbvKVu4=*/
import React, { Component } from 'react';
import {base, high,cardCache,getMultiLang,getBusinessInfo} from 'nc-lightapp-front';
import './index.less'
import { setUserQueryHistory } from '../../../public/components/tradetypeToEmptyArea/addQueryHistory';
import { getNowFormatDate } from '../../../public/components/FormatDateTimeh';

let { setDefData} = cardCache;
const {  Refer } = high;
let { NCButton } = base;
class TradeTypeButton extends Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: true,  //交易类型按钮显示与影藏
            json: {}
        }
    }
    componentWillMount() {
		let callback = (json) => {
			this.setState({json:json});
		}
		getMultiLang({moduleId:'public',domainName :'arap',currentLocale:'simpchn',callback});
	}
    setVisible = (falg) =>{
        this.setState({
            visible:falg
        })
    }

    render() {
        let { billtype, dataSource,switchTemplate,propschil,type,appcode,pagecode,refClass} = this.props;
        return (
           <div className={`${this.state.visible ? 'show' : 'hide'}  teadetype-lightapp-component`}>
                {propschil.getUrlParam('status') =='browse'||type =='list'?(
                <span>
                    <Refer
                        fieldid = "tradetype"
                        placeholder={this.state.json['public-000139']}/* 国际化处理： 交易类型*/
                        refName={this.state.json['public-000151']}/* 国际化处理： 交易类型参照*/
                        refCode={'tradetype'}
                        refType={'grid'}
                        queryGridUrl={'/nccloud/riart/ref/fiBillTypeTableRefAction.do'}
                        columnConfig={[
                            {
                                name: [this.state.json['public-000245'], this.state.json['public-000246']],/* 国际化处理： 交易类型编码,交易类型名称*/
                                code: ['refcode', 'refname']
                            }
                        ]}
                       
                        queryCondition={{
                            GridRefActionExt :(refClass==null||refClass=='undefined')?'nccloud.web.arap.ref.before.TranstypeRefSqlBuilder':refClass,
                            parentbilltype: billtype, //过滤条件
                        }}
                        onChange={(value) => {
                            setDefData('sessionTradeType', dataSource, value.refcode);
                            //是否做过切换交易类型动作，如果做过，卡片返回列表需要重新刷新列表的按钮区域
                            setDefData('isSwitchTradeType',dataSource,true);
                            if(switchTemplate){
                                switchTemplate({code:value.refcode,name:value.refname});
                            }
                            saveTradeTypes(appcode,pagecode,value.refcode);
                        }}
                        isMultiSelectedEnabled={false}
                        clickContainer={<NCButton fieldid="tradetype" colors="primary">{ this.state.json['public-000139']}</NCButton>}/* 国际化处理： 交易类型*/
                    />
                </span>):null}
            </div>
        )
    }
}

function saveTradeTypes(appcode,pagecode,code){
    let params = {
        appcode: appcode,
        pagecode: pagecode,
        historytype: '2',
        recordtime: getNowFormatDate(),
        querycondition: code,
    };
    setUserQueryHistory(params)
}


export default function (props = {}) {
    var conf = {
    };
    
    return <TradeTypeButton {...Object.assign(conf, props)} />
}

/*KypxrnTlCsNW6raC5wgkoL6MjbkvcYxunKIWAbvKVu4=*/